<?php

!defined('IN_ROOT') && exit('Access Denied');

class docmodel {

    var $db;
    var $base;

    function docmodel(&$base) {
        $this->base = $base;
        $this->db = $base->db;
    }
    
    function add($data)
    {
    	return $this->db->insert(DB_TABLEPRE.'doc', $data);
    }
    
    function update($data, $doc_id)
    {
    	if ($data && $doc_id) {
    		$where = " `doc_id`='$doc_id'";
    		return $this->db->update(DB_TABLEPRE.'doc', $data, $where);
    	} else {
    		return false;
    	}
    }
    
    function delete($doc_id) {
    	return $this->db->query("DELETE FROM ".DB_TABLEPRE."doc WHERE `doc_id`='$doc_id'");
    }
    
    function get($doc_id) {
        return $this->db->fetch_first("SELECT * FROM ".DB_TABLEPRE."doc WHERE doc_id='$doc_id'");
    }
    
    function get_list($start=0,$limit=1000, $where='') {
        $linelist=array();
        $query=$this->db->query("SELECT * FROM `".DB_TABLEPRE."doc` WHERE $where ORDER BY `doc_id` DESC limit $start,$limit");
        while($line=$this->db->fetch_array($query)) {
            $linelist[]=$line;
        }
        return $linelist;
    }
	
}
?>
